package com.gamewithpurpose.dbinterface;

import java.util.List;

import org.junit.Test;

import com.gamewithpurpose.dbinterface.POJO.Phrase;

public class PhraseDAOTest extends UnitCommon {
	@Test
	public void testAdd() {
		PhraseDAO.deleteAll();
		
		PhraseDAO.addPhrase("this is a test1");
		PhraseDAO.addPhrase("this is a test2");
		
		List<Phrase> res = PhraseDAO.list();
		
		assertEquals(res.size(), 2);
	}
	
	@Test
	public void testDelete() {
		PhraseDAO.deleteAll();
		List<Phrase> res = PhraseDAO.list();
		assertEquals(res.size(), 0);
		
		PhraseDAO.addPhrase("this is a test1");
		PhraseDAO.addPhrase("this is a test2");
		
		res = PhraseDAO.list();
		
		assertEquals(res.size(), 2);
		
		for (Phrase phrase : res) {
			PhraseDAO.delete(phrase.getId());
		}
		
		res = PhraseDAO.list();
		
		assertEquals(res.size(), 0);
	}
	
	@Test
	public void testExist() {
		PhraseDAO.deleteAll();
		
		PhraseDAO.addPhrase("this is a test1");
		if (!PhraseDAO.isExist("this is a test1"))
			assertTrue(false);
		
		List<Phrase> res = PhraseDAO.list();
		
		assertEquals(res.size(), 1);
	}
}
